import QtQuick 2.0
import QtQuick.Window 2.0
import "../utils.js" as Utils;

Item {
	property string msg: ""
	property bool endWithDestroy: false
	property bool tipMode: false
	signal ok();
	signal cancel();

	id: bg
	width: Utils.AppWin.width
	height: Utils.AppWin.height
	Rectangle {
		anchors.fill: parent
		color: "black"
		opacity: 0.5
	}
	// 模态一下是如此简单，哈哈哈
	MouseArea {
		anchors.fill: parent
		onClicked: {
			if (tipMode)
				bg.visible = false;
		}
	}

	Image {
		id: img
		source: "image://default/dialog/bg.png";
		x: (parent.width - width) / 2
		Text {
			color: "#79f5f3"
			text: bg.msg
			font.pixelSize: 24
			anchors.left: parent.left
			anchors.leftMargin: 140
			anchors.top: parent.top
			anchors.topMargin: 40
			maximumLineCount: 20
		}
		ImgBtn {
			showAni: true
			visible: !tipMode
			source: "image://default/dialog/yes.png"
			x: parent.width / 2 - width + 20
			anchors.bottom: parent.bottom
			anchors.bottomMargin: -height/2
			onClicked: {
				bg.ok();
				if (endWithDestroy)
					bg.destroy();
				else
					bg.visible = false;
			}
		}
		ImgBtn {
			showAni: true
			visible: !tipMode
			source: "image://default/dialog/no.png"
			x: parent.width / 2 + 60
			anchors.bottom: parent.bottom
			anchors.bottomMargin: -height/2
			onClicked: {
				bg.cancel();
				if (endWithDestroy)
					bg.destroy();
				else
					bg.visible = false;
			}
		}
	}

    ParallelAnimation {
		id: showAni
	    running: false
	    PropertyAnimation {target: img; property: "opacity"; duration: 200; from: 0; to:1 }
	    PropertyAnimation {target: img; property: "y"; duration: 200; to: bg.height * 0.4 - img.height / 2}
    }

	onVisibleChanged: {
		if (visible) {
			showAni.start();
		} else {
			img.y = bg.height * 0.6
		}
	}
}

